home *** CD-ROM | disk | FTP | other *** search
/ D.I.S.C. 6 / D.I.S.C. 6.adf / sources / listsort.s < prev    next >
Text File  |  1987-05-04  |  4KB  |  99 lines

  1. ;­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 
  2. ;­ Example for a list- or offset-sort routine ­
  3. ;­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  4. ;Note:
  5. ;This Example is NOT executable. It's just made to give you an example
  6. ;how to realize such a sort-routine. You should better read the 
  7. ;article about this algorithm before trying to understand this!!! 
  8.  
  9. ;Made by Duke/Level Four for D.I.S.C issue #6
  10.  
  11. ;­­­­­­­­­­­­­­­ Statements ­­­­­­­­­­­­­­­
  12.     Anzbobs        =    50    ;amount of bobs/points
  13.     ZMax         =    120    ;max/min  permitted z-value of 
  14.                     ;your points (+-)!
  15.  
  16. S:
  17. Start:    
  18.     ;Example for usage:
  19.     ;------------------
  20.  
  21.     ;At first you've to init all lists and the pointer-tables
  22. ;­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  23. init_sorttabs:
  24.     lea    listsortpt_mi(pc),a0
  25.     lea    listsorttab(pc),a1
  26.     move.w    #Zmax*2,d0        ;for neg. and pos. values
  27. listsortpt_loop:
  28.     move.l    a1,(a0)+        ;store pointer to datalist
  29.     move.l    a1,a2            ;store pointer to...  
  30.     move.l    a2,(a1)            ;...itself at start of datalist
  31.     addi.w    #[anzbobs+1]*4,a1    ;a1=address of next list
  32.     dbf    d0,listsortpt_loop
  33. ;­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  34.  
  35. loop:
  36.     ;Now rotate x,y and z-koord of 1 point of your object by 
  37.     ;using your standard vector-routine and then...
  38.  
  39. ;­­­­­­­­­­­­­­­­­­ Store x- and y-koord in list ­­­­­­­­­­­­­­­­­­­­
  40. ;d0=x-koord, d1=y-koord, d2=z-koord (after rotation,translation and 
  41. ;projection!)
  42.  
  43.     lea    listsortpt(pc),a1 ;a1=address of table of listpointers
  44.     andi.w    #-2,d2        ;force even z-value
  45.     add.w    d2,d2        ;d2=d2*2 (z-koord must be divisible by
  46.                 ;4 without rest, because one pointer
  47.                 ;is 4 bytes long (of course))
  48.     add.w    d2,a1        ;z-koord is now used as offset(addition
  49.                 ;or subtraction depends on sign (+-)!)
  50.     move.l    (a1),a1        ;a1=address of correct list for koords
  51.     addq.l    #4,(a1)        ;correct pointer (old pointer +2 words
  52.                 ;to skip last x- and y-koord!)
  53.     move.l    (a1),a1        ;a1=correct destination-address
  54.     movem.w    d0/d1,(a1)    ;store x and y-koord (2 words)
  55. ;­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  56.  
  57.     ;now rotate all remaining points and store them in this way!
  58.  
  59.     ;and when you've done this you must...
  60.  
  61. ;­­­­­­­­­­­­­­­­­­ Fetch right koords (and blit bobs) ­­­­­­­­­­­­­­­­
  62.  
  63.     lea    listsortptend(pc),a0 ;a0=end of table of listpointers
  64.     move.w    #Zmax*2,d3    ;amount of possible z-values (+-)
  65. make_list:
  66.     move.l    (a0),a1        ;a1=address of list
  67.     subq.w    #4,a0        ;a0=address of next listpointer
  68.     move.l    (a1),a2        ;a2 points on last stored koords in list
  69.     cmp.l    a1,a2        ;does a2 point on itself?
  70.     bhi.s    fetch_koords    ;if not (a2 > a1) go and fetch koords!
  71.     subq.w    #1,d3        ;otherwise go on searching koords
  72.     bne.s    make_list    ;if d3=0 then ....
  73.     bra.s    exit_search    ;....stop searching!
  74. fetch_koords:
  75.     movem.w    (a2),d0/d1    ;d0=x-koord/d1=y-koord
  76.     subq.w    #4,a2        ;a2=address of next koords
  77.  
  78. blit_bob:
  79. ;­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  80. ;           Here/now you should blit the bob!
  81. ;­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  82.     cmp.l    a1,a2        ;are there any koords left in list?
  83.     bgt.s    fetch_koords    ;yeah -> fetch next koords!
  84. mb_nextz:
  85.     move.l    a1,(a1)        ;restore startpointer in list
  86.     subq.w    #1,d3
  87.     bne.s    make_list    ;go on searching
  88. exit_search:
  89.     Rts
  90. ;­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  91.  
  92.  
  93. listsortpt_mi:    blk.l Zmax    ;pointers to lists for points
  94.                 ;with negative z-koords
  95. listsortpt:    blk.l Zmax+1    ;pointers to lists for points
  96.                 ;with positive z-koords
  97. listsortptend:
  98. listsorttab:    blk.l [Zmax*2+1]*[anzbobs+1] ;table of lists
  99.